package org.example.controller;

import org.example.entity.TeacherEntity;
import org.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/teachers")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    // 增加老师
    @PostMapping("/add")
    public boolean addTeacher(@RequestBody TeacherEntity teacherEntity) {
        return teacherService.addTeacher(teacherEntity);
    }

    // 删除老师
    @DeleteMapping("/{id}")
    public boolean deleteTeacher(@PathVariable("id") Integer teacherId) {
        return teacherService.deleteTeacher(teacherId);
    }

    // 更新老师信息
    @PutMapping
    public boolean updateTeacher(@RequestBody TeacherEntity teacherEntity) {
        return teacherService.updateTeacher(teacherEntity);
    }

    // 获取老师信息
    @GetMapping("/{id}")
    public TeacherEntity getTeacher(@PathVariable("id") Integer teacherId) {
        return teacherService.getTeacherById(teacherId);
    }

    // 获取所有老师
    @GetMapping
    public List<TeacherEntity> getAllTeachers() {
        return teacherService.getAllTeachers();
    }

    // 老师登录
    @PostMapping("/login")
    public TeacherEntity login(@RequestBody Map<String, String> teacherInfo) {
        String username = teacherInfo.get("username");
        String password = teacherInfo.get("password");
        return teacherService.login(username, password);
    }
}
